package com.hx.petsever.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hx.petsever.entity.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper extends BaseMapper<Address> {

    @Insert("INSERT INTO address SET NAME = #{name}, phone = #{phone},address = #{address} ,userid = #{userid},defaults = #{defaults}")
    void InsertAddress (@Param("name") String name , @Param("phone") String phone ,
                        @Param("address") String address ,@Param("userid") String userid,
                        @Param("defaults") String defaults);

    @Select("SELECT NAME , phone , address , defaults FROM address WHERE userid = #{userid} ")
    List<Address> getAllbyId(@Param("userid") String userid);

    @Delete("DELETE FROM address WHERE NAME = #{name} and phone = #{phone} and address = #{address} and userid = #{userid}")
    void DeleteOne(@Param("name") String name , @Param("phone") String phone ,
                   @Param("address") String address ,@Param("userid") String userid);

    @Select("SELECT NAME , phone , address , userid FROM address WHERE NAME = #{name} and phone = #{phone} and address = #{address} and userid = #{userid}")
    Address getOn(@Param("name") String name , @Param("phone") String phone ,
                  @Param("address") String address ,@Param("userid") String userid);

    @Update("UPDATE  address SET defaults = #{defaults} WHERE NAME = #{name} and phone = #{phone} and address = #{address} and userid = #{userid}")
    void updateDefaults(@Param("name") String name , @Param("phone") String phone ,
                        @Param("address") String address ,@Param("userid") String userid,
                        @Param("defaults") String defaults);
}
